﻿using STHPMS1.BLL.B_Core;
using STHPMS1.ICore.I_BLL.Bus;
using STHPMS1.ICore.I_Entity.Info;
using STHPMS1.ICore.I_Entity.Stmpms1;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using STHPMS1.Common.C_Entity.Stmpms1;
namespace STHPMS1.BLL.B_Bus
{
    public class E_SegevaluBus : BllBase, IE_SegevaluBill
    {
        public void Save<T>(T entity)
            where T : class ,IE_Segevalu
        {
            this.Scene.Dal.Sthpms1.Save(entity);
        }

        public void Remove(IE_Segevalu entity)
        {
            this.Scene.Dal.Sthpms1.Delete(entity);
        }

        public IEnumerable<T> Get<T>(Expression<Func<T, bool>> predicate, IPagingInfo info)
            where T : class, IE_Segevalu
        {
            return this.Scene.Dal.Sthpms1.Select<T>(predicate, info);
        }

        /// <summary>
        /// 更新路段评定中不同指标的值
        /// </summary>
        /// <param name="inspecid">评定名称</param>
        /// <param name="segid">基础路段ID</param>
        /// <param name="rdwayid">路线编号</param>
        /// <param name="type">指标</param>
        /// <param name="value">指标值</param>
        public void Update(string inspecid, string segid, string rdwayid, string type, double value)
        {
            this.Scene.Dal.Sthpms1.E_Segevalu.Update(inspecid, segid, rdwayid, type, value);
        }


        #region 获取路段的评定值
        /// <summary>
        /// 获取路段的评定值
        /// </summary>
        /// <param name="inspecid">评定名称</param>
        /// <param name="rdwayid">路线编号</param>
        /// <param name="Type">PCI,RDI,RQI,SRI</param>
        /// <returns></returns>
        public Dictionary<string, double> GetSegidValue(string inspecid, string rdwayid, string Type)
        {
            return this.Scene.Dal.Sthpms1.E_Segevalu.GetSegidValue(inspecid, rdwayid, Type);
        }
        #endregion 



        //#region 保存路段评定  待删除
        //public void SaveSegEvalu(string inspecid)
        //{
        //    List<string> list = GetRdwayID(inspecid);
        //    foreach (string rdwayid in list)
        //    {
        //        SegEvaluInsert(inspecid, rdwayid, "PCI");
        //        SegEvaluInsert(inspecid, rdwayid, "RDI");
        //        SegEvaluInsert(inspecid, rdwayid, "RQI");
        //        SegEvaluInsert(inspecid, rdwayid, "SRI");
        //        SegEvaluInsert(inspecid, rdwayid, "PSSI");
        //        SegEvaluInsert(inspecid, rdwayid, "SCI");
        //        SegEvaluInsert(inspecid, rdwayid, "BCI");
        //        SegEvaluInsert(inspecid, rdwayid, "TCI");
        //        SegEvaluInsert(inspecid, rdwayid, "PQI");
        //        SegEvaluInsert(inspecid, rdwayid, "MQI");
        //    }
        //}


        //public void SegEvaluInsert(string inspecid, string rdwayid, string type)
        //{
        //    Dictionary<string, double> dict = this.Scene.Bll.E_Segevalu.GetSegidValue(inspecid, rdwayid, type);
        //    foreach (var item in dict)
        //    {
        //        string segid = item.Key;
        //        double value = item.Value;

        //        E_Segevalu info = new E_Segevalu();
        //        info.Inspecid = inspecid;
        //        info.Segid = segid;
        //        info.Rdwayid = rdwayid;
        //        info.Direction_Dictid = this.Scene.Dal.Sthpms1.Single<B_Invntory>(x => x.Segid == segid).Direction_Dictid;
        //        info.Pci = value;
        //        int count = this.Scene.Bll.E_Segevalu.Get<E_Segevalu>(q => q.Inspecid == inspecid && q.Segid == segid && q.Rdwayid == rdwayid, null).Count();
        //        if (count >= 1)
        //        {
        //            this.Scene.Bll.E_Segevalu.Update(inspecid, segid, rdwayid, type, value);
        //        }
        //        else
        //        {
        //            this.Scene.Dal.Sthpms1.Insert<E_Segevalu>(info);
        //        }
        //    }
        //}
        //#endregion
        
    }
}
